home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 671 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  918 b 

  1. Path: news.informatik.uni-kiel.de!ma
  2. From: ma@informatik.uni-kiel.de (Martin Ameskamp)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to print a enum variable's names
  5. Date: 5 Jan 1996 18:44:55 GMT
  6. Organization: Dept. of Computer Science, University of Kiel, FRG
  7. Message-ID: <4cjrj7$gr8@gutemine.informatik.uni-kiel.de>
  8. References: <4cjohq$k5u@lsi.lsil.com>
  9. NNTP-Posting-Host: rigel.informatik.uni-kiel.de
  10.  
  11. In <4cjohq$k5u@lsi.lsil.com> song@lsil.com (Song Liang) writes:
  12.  
  13. >  Suppose you have a variable foo of type "enum bar_type {CAR TRUCK VAN}", if 
  14. >you do "cout << foo", it will print either 0, 1 or 2.  Is there a simple trick
  15. >to print the names, i.e CAR, TRUCK or VAN?
  16.  
  17. >  Thanks in advance.
  18.  
  19.     Yes: :-)
  20.  
  21.     switch (foo){
  22.       case CAR:    cout << "CAR"; break;
  23.       case TRUCK:    cout << "TRUCK"; break;
  24.       case VAN:    cout << "VAN"; break;
  25.     }
  26.  
  27.     Probably not what you wanted, but there's no 'automatic' way
  28.     to do this.
  29.  
  30.     Martin
  31.